package com.irdstudio.cdp.pboc.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.cdp.pboc.service.dao.PbocCreditStatusDao;
import com.irdstudio.cdp.pboc.service.domain.PbocCreditStatus;
import com.irdstudio.cdp.pboc.service.facade.PbocCreditStatusService;
import com.irdstudio.cdp.pboc.service.vo.PbocCreditStatusVO;
import com.irdstudio.basic.framework.core.base.FrameworkService;
/**
 * <p>ServiceImpl: 贷记卡状态信息				<p>
 * @author ligm
 * @date 2018-12-26
 */
@Service("pbocCreditStatusService")
public class PbocCreditStatusServiceImpl implements PbocCreditStatusService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(PbocCreditStatusServiceImpl.class);

	@Autowired
	private PbocCreditStatusDao pbocCreditStatusDao;
	
	/**
	 * 新增操作
	 */
	public int insertPbocCreditStatus(PbocCreditStatusVO inPbocCreditStatusVo)  throws Exception {
		logger.debug("当前新增数据为:"+ inPbocCreditStatusVo.toString());
		int num = 0;
		try {
			PbocCreditStatus pbocCreditStatus = new PbocCreditStatus();
			beanCopy(inPbocCreditStatusVo, pbocCreditStatus);
			num = pbocCreditStatusDao.insertPbocCreditStatus(pbocCreditStatus);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(PbocCreditStatusVO inPbocCreditStatusVo)  throws Exception {
		logger.debug("当前删除数据条件为:"+ inPbocCreditStatusVo);
		int num = 0;
		try {
			PbocCreditStatus pbocCreditStatus = new PbocCreditStatus();
			beanCopy(inPbocCreditStatusVo, pbocCreditStatus);
			num = pbocCreditStatusDao.deleteByPk(pbocCreditStatus);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocCreditStatusVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(PbocCreditStatusVO inPbocCreditStatusVo)  throws Exception {
		logger.debug("当前修改数据为:"+ inPbocCreditStatusVo.toString());
		int num = 0;
		try {
			PbocCreditStatus pbocCreditStatus = new PbocCreditStatus();
			beanCopy(inPbocCreditStatusVo, pbocCreditStatus);
			num = pbocCreditStatusDao.updateByPk(pbocCreditStatus);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocCreditStatusVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public PbocCreditStatusVO queryByPk(PbocCreditStatusVO inPbocCreditStatusVo) {
		
		logger.debug("当前查询参数信息为:"+ inPbocCreditStatusVo);
		try {
			PbocCreditStatus queryPbocCreditStatus = new PbocCreditStatus();
			beanCopy(inPbocCreditStatusVo, queryPbocCreditStatus);
			PbocCreditStatus queryRslPbocCreditStatus = pbocCreditStatusDao.queryByPk(queryPbocCreditStatus);
			if (Objects.nonNull(queryRslPbocCreditStatus)) {
				PbocCreditStatusVO outPbocCreditStatusVo = beanCopy(queryRslPbocCreditStatus, new PbocCreditStatusVO());
				logger.debug("当前查询结果为:"+ outPbocCreditStatusVo.toString());
				return outPbocCreditStatusVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
			throw e;
		}
		return null;
	}
	
	@Override
	public PbocCreditStatusVO selectByFId(String fid) {
		logger.debug("当前查询参数信息为:"+ fid);
		try {
			PbocCreditStatus queryRslPbocCreditStatus = pbocCreditStatusDao.selectByFId(fid);
			if (Objects.nonNull(queryRslPbocCreditStatus)) {
				PbocCreditStatusVO outPbocCreditStatusVo = beanCopy(queryRslPbocCreditStatus, new PbocCreditStatusVO());
				logger.debug("当前查询结果为:"+ outPbocCreditStatusVo.toString());
				return outPbocCreditStatusVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
			throw e;
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocCreditStatusVO> queryAllOwner(PbocCreditStatusVO pbocCreditStatusVo)  throws Exception {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PbocCreditStatusVO> list = null;
		try {
			List<PbocCreditStatus> pbocCreditStatuss = pbocCreditStatusDao.queryAllOwnerByPage(pbocCreditStatusVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pbocCreditStatuss.size());
			pageSet(pbocCreditStatuss, pbocCreditStatusVo);
			list = (List<PbocCreditStatusVO>) beansCopy(pbocCreditStatuss, PbocCreditStatusVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocCreditStatusVO> queryAllCurrOrg(PbocCreditStatusVO pbocCreditStatusVo)  throws Exception {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<PbocCreditStatus> pbocCreditStatuss = pbocCreditStatusDao.queryAllCurrOrgByPage(pbocCreditStatusVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+pbocCreditStatuss.size());
		List<PbocCreditStatusVO> list = null;
		try {
			pageSet(pbocCreditStatuss, pbocCreditStatusVo);
			list = (List<PbocCreditStatusVO>) beansCopy(pbocCreditStatuss, PbocCreditStatusVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocCreditStatusVO> queryAllCurrDownOrg(PbocCreditStatusVO pbocCreditStatusVo)  throws Exception {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<PbocCreditStatus> pbocCreditStatuss = pbocCreditStatusDao.queryAllCurrDownOrgByPage(pbocCreditStatusVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ pbocCreditStatuss.size());
		List<PbocCreditStatusVO> list = null;
		try {
			pageSet(pbocCreditStatuss, pbocCreditStatusVo);
			list = (List<PbocCreditStatusVO>) beansCopy(pbocCreditStatuss, PbocCreditStatusVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}
	/**
	 * 需求编号:2019D0519
	 * 问题编号:
	 * 开发人员: caoxin
	 * 创建日期:2019/7/19
	 * 功能描述:贷记卡状态记录
	 * 修改日期:2019/7/19
	 * 修改描述:
	 */
	@Override
	public List<PbocCreditStatusVO> selectByFIdS(List<String> fids) {
		logger.debug("当前查询参数信息为:"+ fids);
		List<PbocCreditStatusVO> list = null;
		try {
			List<PbocCreditStatus> pbocCreditStatus = pbocCreditStatusDao.selectByFIdS(fids);
			list = (List<PbocCreditStatusVO>) beansCopy(pbocCreditStatus, PbocCreditStatusVO.class);
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return list;
	}
}
